package com.gupao.bio;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @基本功能:
 * @program:gupao-netty
 * @author: jiawy
 * @create:2024-10-10 17:41:19
 **/
public class BlockingServerTest {

    final static ExecutorService exec = Executors.newCachedThreadPool();

    public static void main(String[] args) throws Exception {

        ServerSocket serverSocket = new ServerSocket(8080);
        while(true){
            Socket socket = serverSocket.accept();

            exec.execute(() ->{
            try {
                System.out.println("客户端端口号：" + socket.getPort());

                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

                String cliStr = null;

                    cliStr = bufferedReader.readLine();


                System.out.println("收到客户端数据："+ cliStr);

                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                bufferedWriter.write("ok\n");

                bufferedWriter.flush();
            } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            });


        }

    }
}